// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db=cloud.database();
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  var num=event.num
  var page=event.page
  var sectionClass=event.sectionClass
  const wxContext = cloud.getWXContext()
  if(sectionClass.length!=0){
    return await db.collection("topic")
  .skip(page)
  .limit(num)
  .orderBy('lastReplytime','desc')
  .where({
    sID:sectionClass
  }).get()

  }
  return await db.collection("topic")
  .skip(page)
  .limit(num)
  .orderBy('lastReplytime','desc')
  .where({
    _openid:wxContext.OPENID
  }).get()
}
